#define row1() init_lcd(0x80)	/* Begin at Line 1 */
#define row2() init_lcd(0xC0)   /* Begin at Line 2 */
#define LCD_Clear() init_lcd(0x01)	/* Clear display LCD */
unsigned char w[] = { 0x38,0x0c,0x01,0x06,0x02,0x80};
unsigned char temp,brk;
int32 increase_rot=0;
int32 dum,increase,dummy;
unsigned char i;
byte const val[]={'0','1','2','3','4','5','6','7','8','9'};

/*======================================================LCD Initialisation============================================*/
void init_lcd(unsigned char j)
{
   output_e (0x00);
   output_d (j);
   output_e (0x02);
   delay_ms (2);
   output_e (0x00);
   delay_ms (2);
}
/*=======================================================Display Function=============================================*/
void display(char s)
{
   output_e (0x01);
   output_d (s);
   output_e (0x03);
   delay_ms (2);
   output_e (0x01);
   delay_ms (2);
}
/*=======================================================Functions For ROW============================================*/
void Lcd_init()
{
   for( i = 0 ; i < 6 ; i++ )
   {
      init_lcd (w[i]);
   }
}

/*================================================Function to display data on LCD=====================================*/
void LCD_RTC(unsigned char k)
{
   output_e (0x01);
   output_d (((k/16)%10)+0X30);
   output_e (0x03);
   delay_us (10);
   output_e (0x01);
   delay_us (100);

   output_e (0x01);
   output_d ((k%16)+0X30);
   output_e (0x03);
   delay_us (10);
   output_e (0x01);
   delay_us (100);
}

void LCD_digital(unsigned char k)
{
   output_e (0x01);
   output_d (((k/10)%10)+0X30);
   output_e (0x03);
   delay_us (10);
   output_e (0x01);
   delay_us (100);

   output_e (0x01);
   output_d ((k%10)+0X30);
   output_e (0x03);
   delay_us (10);
   output_e (0x01);
   delay_us (100);
}

/*=======================================================================================================================
                                                          Buzzer
======================================================================================================================*/

void buzzer(unsigned char loop, int tone)
{
   unsigned char beep;
   for(beep=0;beep<loop;beep++)
   {
      output_high(PIN_C5);
      delay_ms(tone);
      output_low(PIN_C5);
      delay_ms(tone);
   }
}

int dec_to_hex(int val)
{
   return ((val/10)*16)+(val%10);
}


timemode_call(int deg)
{
   increase_rot=0;
   brk=0;
   while(brk!=1)
   {
 /*==========================================================Time Increase============================================*/
      if(input(UP) == SELECT)
      {
         increase_rot=increase_rot+1;
         if(((deg==1)&&(increase_rot==24)) || ((deg==2)&&(increase_rot==60)) || ((deg==3)&&(increase_rot==60)))
            increase_rot=0;
         init_lcd(0xC0+((deg-1)*3));
         dum=increase=increase_rot;
         increase=increase/10;
         dummy=increase+48;
         display(dummy);
         delay_us(10);
         dum=dum%10;
         dummy=dum+48;
         display(dummy);
         delay_ms(500);
      }
/*==========================================================Time Decrease=============================================*/
       /* For Hours Setting*/
       /*Set Key should be pressed after entering the value*/

      if(input(DOWN) == SELECT)
      {
         increase_rot=increase_rot-1;
         if(deg==1 && increase_rot==-1)
            increase_rot=23;
         if(deg==2 && increase_rot==-1)
            increase_rot=59;
         if(deg==3 && increase_rot==-1)
            increase_rot=59;
         init_lcd(0xC0+((deg-1)*3));
         dum=increase=increase_rot;
         increase=increase/10;
         dummy=increase+48;
         display(dummy);
         delay_us(10);
         dum=dum%10;
         dummy=dum+48;
         display(dummy);
         delay_ms(500);
      }
/*============================================================Time Set================================================*/
      else if(input(EXIT) == SELECT)
      {
         brk=1;
         break;
      }
   }
   /*Returns the value of count to the time_mode function*/
   return(increase_rot);
}
